#pragma once
#include "EngineHeader.h"

namespace LSH
{

    Graphics::VertexBuffer* g_pTriVB = NULL;
    Graphics::IndexBuffer* g_pTriIB = NULL;
    #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE)

    struct CUSTOMVERTEX
    {
        FLOAT x, y, z;      // Position
        DWORD color;        // The vertex color.
    };

    inline void testTriangle()
    {
        CUSTOMVERTEX vertices[] =
        {
            { -25.0f, -25.0f, 40.0f, 0xffff0000, }, // x, y, z, color
            {   0.0f,  25.0f, 40.0f, 0xff00ff00, },
            {  25.0f, -25.0f, 40.0f, 0xff00ffff, },
        };

        g_pTriVB = CM_NEW(Graphics::VertexBuffer); 

        int byteSize = sizeof(CUSTOMVERTEX) * ARRAYSIZE(vertices);

        g_pTriVB->create(byteSize, ARRAYSIZE(vertices), D3DFVF_CUSTOMVERTEX);

        g_pTriVB->map(vertices, byteSize);

        WORD indexs[] = {0, 1, 2};

        g_pTriIB = CM_NEW(Graphics::IndexBuffer);

        byteSize = sizeof(WORD) * ARRAYSIZE(indexs);

        g_pTriIB->create(byteSize);

        g_pTriIB->map(indexs, byteSize);
    }


    inline void renderTriangle()
    {
        IDirect3DDevice9* pD3dDevice = Graphics::Render::getSingleton().getD3DDevice();

        g_pTriVB->setAsStreamSource();

        g_pTriIB->setAsIndicesSource();

         //pD3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
            
        pD3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 3, 0, 1);

           
        //D3DXMATRIX matWorld;
        //pD3dDevice->GetTransform(D3DTS_WORLD, &matWorld);

        //D3DXMATRIX move;
        //D3DXMatrixIdentity(&move);
        //D3DXMatrixTranslation(&move, 5, 0, 6);
        //pD3dDevice->SetTransform(D3DTS_WORLD, &move);

        //pD3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 3, 0, 1);

        //pD3dDevice->SetTransform(D3DTS_WORLD, &matWorld);
    }

} // end LSH




